package org.mcb.zebra.portal.context;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.Set;
import java.util.Vector;

import javax.portlet.PortalContext;

import org.apache.pluto.util.Enumerator;
import org.mcb.zebra.portal.resource.ResourceConfig;

@SuppressWarnings("unchecked")
public class ZebPortalContext implements PortalContext {
	private ResourceConfig config;
	private HashMap properties = new HashMap();

	public ZebPortalContext(ResourceConfig config) {
		this.config = config;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.portlet.PortalContext#getPortalInfo()
	 */
	public String getPortalInfo() {
		return config == null ? null : config.getPortalInfo();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.portlet.PortalContext#getProperty(java.lang.String)
	 */
	public String getProperty(String name) {
		if (name == null) {
			throw new IllegalArgumentException("Property name == null");
		}

		return (String) properties.get(name);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.portlet.PortalContext#getPropertyNames()
	 */
	public Enumeration getPropertyNames() {
		Vector names = new Vector(properties.keySet());
		return names.elements();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.portlet.PortalContext#getSupportedPortletModes()
	 */
	public Enumeration getSupportedPortletModes() {
		if (config == null)
			return null;
		Set set = config.getSupportedPortletModes();
		if (set == null)
			return null;
		return new Enumerator(set);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.portlet.PortalContext#getSupportedWindowStates()
	 */
	public Enumeration getSupportedWindowStates() {
		if (config == null)
			return null;
		Set set = config.getSupportedWindowStates();
		if (set == null)
			return null;
		return new Enumerator(set);
	}

	/**
	 * Thêm các thông tin vào portal
	 * 
	 * @param name
	 *            khóa
	 * @param value
	 *            nội dung
	 */
	public void setProperty(String name, String value) {
		if (name == null) {
			throw new IllegalArgumentException("Property name == null");
		}

		properties.put(name, value);
	}

}
